import Constants from "../constants"

export function encodeChatMessage(toId,contactId,msg) {
    let msgJson = {}
    msgJson[Constants.PROPERTY_TYPE] = Constants.TYPE_CHAT
    let content = []
    content.push(Constants.Chat.MSG_TEXT)
    content.push(contactId)
    content.push(toId)
    content.push(msg)
    msgJson[Constants.PROPERTY_CONTENT] = content
    return JSON.stringify(msgJson)
}


export function encodeContactMessage(type,payload) {
    let msgJson = {}
    msgJson[Constants.PROPERTY_TYPE] = Constants.TYPE_CONTACT
    let content = {}
    content[Constants.Contact.PROPERTY_CMD_TYPE] = type
    content[Constants.Contact.PROPERTY_PAYLOAD] = payload
    msgJson[Constants.PROPERTY_CONTENT] = content
    return JSON.stringify(msgJson)
}


export function encodeRtcConnectMessage(toId,type,payload) {
    let msgJson = {}
    msgJson[Constants.PROPERTY_TYPE] = Constants.TYPE_RTC_CONNECT
    let content = {}
    content[Constants.Rtc.PROPERTY_CMD_TYPE] = type
    content[Constants.Rtc.PROPERTY_REMOTE] = toId
    content[Constants.Rtc.PROPERTY_PAYLOAD] = payload
    msgJson[Constants.PROPERTY_CONTENT] = content
    return JSON.stringify(msgJson)
}

